package ink.lovejinhu.swardToOffer;

import ink.lovejinhu.common.ListNode;

/**
 * @author jinhu
 * created 2021-08-18 9:08
 */
public class Offer_018 {
    /**
     * 删除链表中的节点
     *
     * @param head
     * @param val
     * @return
     */
    public ListNode deleteNode(ListNode head, int val) {
        if (head == null) {
            return null;
        }
        ListNode pre = new ListNode(Integer.MAX_VALUE);
        pre.next = head;
        ListNode new_head = pre;
        while (head != null) {
            if (head.val == val) {
                pre.next = head.next;
                head = head.next;
            } else {
                pre = head;
                head = head.next;
            }
        }
        return new_head.next;

    }
}
